import fmUtil from './formatUtil'

export default class DateUtil {

    static getThisWeek() {
        let now = new Date();
        let nowMonth = now.getMonth(); //当前月
        let nowYear = now.getFullYear(); //当前年
        let nowDayOfWeek = now.getDay(); //今天本周的第几天
        let nowDay = now.getDate(); //当前日

        let weekStart = new Date(now.setFullYear(nowYear, nowMonth,nowDay - nowDayOfWeek+1))
        let weekEnd = new Date(now.setFullYear(nowYear, nowMonth, nowDay + (7 - nowDayOfWeek)))
        weekStart.setHours(0,0,0)
        weekEnd.setHours(23,59,59)
        let arr = []
        arr.push(weekStart)
        arr.push(weekEnd)
        console.log('[week arr]',arr)
        return arr
    }

    static getToday() {
        let arr = []
        let now = new Date();
        let dayStart =  new Date(now.setHours(0,0,0))
        let dayEnd = new Date(now.setHours(23,59,59))
        arr.push(dayStart)
        arr.push(dayEnd)
        console.log('[arr]',arr)
        return arr;
    }

    static getThisMonth() {
        let now = new Date();
        let nowMonth = now.getMonth(); //当前月
        let nowYear = now.getFullYear(); //当前年
        let monthStart = new Date(now.setFullYear( nowYear, nowMonth, 1));
        let monthEnd = new Date(now.setFullYear( nowYear, nowMonth, this.getMonthDays(nowYear,nowMonth)));
        monthStart.setHours(0,0,0)
        monthEnd.setHours(23,59,59)
        let arr = []
        arr.push(monthStart)
        arr.push(monthEnd)
        console.log('[thisMonth]',arr)
        return arr;
    }

    static getMonthDays(nowYear,myMonth) {
        let monthStartDate = new Date(nowYear, myMonth, 1);
        let monthEndDate = new Date(nowYear, myMonth + 1, 1);
        let days = (monthEndDate - monthStartDate)/(1000 * 60 * 60 * 24);
        return days;
    }

    static getLastMonth() {
        let now = new Date();
        let nowYear = now.getFullYear(); //当前年

        let lastMonthDate = new Date(); //上月日期
        lastMonthDate.setDate(1);
        lastMonthDate.setMonth(lastMonthDate.getMonth()-1);
        let lastMonth = lastMonthDate.getMonth();

        let lastMonthStart = new Date(now.setFullYear(nowYear, lastMonth, 1));
        let lastMonthEndDate = new Date(now.setFullYear(nowYear, lastMonth, this.getMonthDays(nowYear,lastMonth)));
        lastMonthStart.setHours(0,0,0)
        lastMonthEndDate.setHours(23,59,59)
        let arr = []
        arr.push(lastMonthStart)
        arr.push(lastMonthEndDate)
        console.log('[lastMonth]',arr)
        return arr
    }
}